# Django settings for jrittc project.
import socket
import os
#import logging.handlers

# If production server 
# @todo: change to local 
if socket.gethostname() == "jrc-web01.vappx.com":
    DEBUG = True
    TEMPLATE_DEBUG = True

#    DEBUG = True
#    TEMPLATE_DEBUG = DEBUG

    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
            'NAME': 'jrcdjango',                      # Or path to database file if using sqlite3.
            'USER': 'jrcweb01',                      # Not used with sqlite3.
            'PASSWORD': '7SKf3LqYJwjpZMGh',                  # Not used with sqlite3.
            'HOST': '',                      # Set to empty string for localhost. Not used with sqlite3.
            'PORT': '',                      # Set to empty string for default. Not used with sqlite3.
        }
    }
    
    INTERNAL_IPS = ()

else:
    DEBUG = True
    TEMPLATE_DEBUG = DEBUG
    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
            'NAME': 'c:/_projects/ittc/jrc.db',                      # Or path to database file if using sqlite3.
            'USER': '',                      # Not used with sqlite3.
            'PASSWORD': '',                  # Not used with sqlite3.
            'HOST': '',                      # Set to empty string for localhost. Not used with sqlite3.
            'PORT': '',                      # Set to empty string for default. Not used with sqlite3.
        }
    }
    
    INTERNAL_IPS = ('127.0.0.1')

#DEBUG = False
#TEMPLATE_DEBUG = False

ADMINS = (
    ('Admin', 'jrcprog@gmail.com'),
)

MANAGERS = ADMINS

# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
# although not all choices may be available on all operating systems.
# On Unix systems, a value of None will cause Django to use the same
# timezone as the operating system.
# If running in a Windows environment this must be set to the same as your
# system time zone.
#TIME_ZONE = 'Europe/Berlin'
TIME_ZONE = 'GMT'

# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
LANGUAGE_CODE = 'en-us'

SITE_ID = 1

# If you set this to False, Django will make some optimizations so as not
# to load the internationalization machinery.
USE_I18N = True

# If you set this to False, Django will not format dates, numbers and
# calendars according to the current locale
USE_L10N = True

# @todo: Change to local for developper
if socket.gethostname() != "jrc-web01.vappx.com":

    # Absolute filesystem path to the directory that will hold user-uploaded files.
    # Example: "/home/media/media.lawrence.com/"
    MEDIA_ROOT = 'c:/_projects/ittc/uploads/'
    
    TEMPLATE_DIRS = (
        "c:/_projects/ittc/templates"                 
    )

else:
    # Absolute filesystem path to the directory that will hold user-uploaded files.
    # Example: "/home/media/media.lawrence.com/"
    MEDIA_ROOT = '/home/jrcweb01/ittc/uploads/'

    TEMPLATE_DIRS = (
        "/home/jrcweb01/ittc/templates"                 
    )


# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash if there is a path component (optional in other cases).
# Examples: "http://media.lawrence.com", "http://example.com/media/"
MEDIA_URL = 'http://jrc.play-and-think.com/'

# URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a
# trailing slash.
# Examples: "http://foo.com/media/", "/media/".
#ADMIN_MEDIA_PREFIX = '/media/'
ADMIN_MEDIA_PREFIX = 'http://jrc.play-and-think.com/media/'

# Make this unique, and don't share it with anybody.
SECRET_KEY = 'zwx35+48*3m6u*87tnfs_me0_7s%^&qaoes!kr@)hgf(w119ax'

# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
    'django.template.loaders.filesystem.Loader',
    'django.template.loaders.app_directories.Loader',
#     'django.template.loaders.eggs.Loader',
)

STATICFILES_DIRS = (
    "c:\_projects\ittc\doc"
)

ROOT_URLCONF = 'src.urls'

if socket.gethostname() == "jrc-web01.vappx.com":
    MIDDLEWARE_CLASSES = (
#        'debug_toolbar.middleware.DebugToolbarMiddleware',
        'django.middleware.common.CommonMiddleware',
        'django.contrib.sessions.middleware.SessionMiddleware',
        'django.middleware.csrf.CsrfViewMiddleware',
        'django.contrib.auth.middleware.AuthenticationMiddleware',
        'django.contrib.messages.middleware.MessageMiddleware',
    )
    
    INSTALLED_APPS = (
        'django.contrib.auth',
        'django.contrib.contenttypes',
        'django.contrib.sessions',
        'django.contrib.sites',
        'django.contrib.messages',
        
        "jrcmodel",
        "ittctalk",
        "pet",
        "jrcsignal",
    #    "asset",
    #    "tsp",
    #    "accounts",
        "tracking",
        "parameter",
        "jrcconfig",
        "maintain",
        "help",
        "jrcshared",
        "tradinglist", 
        "ximport",
        "test",
        "xport",
        
        # Debug toolbar
#        "debug_toolbar",
        
        # Uncomment the next line to enable the admin:
        'django.contrib.admin',
        # Uncomment the next line to enable admin documentation:
        # 'django.contrib.admindocs',
    )

else:
    MIDDLEWARE_CLASSES = (
        'debug_toolbar.middleware.DebugToolbarMiddleware',
#        'src.middleware.WebDebugToolbarMiddleware',
        'django.middleware.common.CommonMiddleware',
        'django.contrib.sessions.middleware.SessionMiddleware',
        'django.middleware.csrf.CsrfViewMiddleware',
        'django.contrib.auth.middleware.AuthenticationMiddleware',
        'django.contrib.messages.middleware.MessageMiddleware',
    )
    
    INSTALLED_APPS = (
        'django.contrib.auth',
        'django.contrib.contenttypes',
        'django.contrib.sessions',
        'django.contrib.sites',
        'django.contrib.messages',
        
        "jrcmodel",
        "ittctalk",
        "pet",
        "jrcsignal",
        "por1",
    #    "asset",
    #    "tsp",
    #    "accounts",
        "tracking",
        "parameter",
        "jrcconfig",
        "maintain",
        "help",
        "jrcshared",
        "tradinglist", 
        "ximport",
        "jrcuser",
        "test",
        "xport",
        
        # Debug toolbar
        "debug_toolbar",
        
        
        # Uncomment the next line to enable the admin:
        'django.contrib.admin',
        # Uncomment the next line to enable admin documentation:
        # 'django.contrib.admindocs',
    )

# END ELSE IF (jrcweb)

# Django debug toolbar
DEBUG_TOOLBAR_CONFIG = {
    'INTERCEPT_REDIRECTS': False
}


LOGGING = {
    "version": 1
    , "disable_existing_loggers": True
    , "formatters": {
        "verbose": {
            "format": "%(asctime)s [%(levelname)s] (%(name)s:%(lineno)s) %(message)s"
            , "datefmt": "%Y-%m-%d %H:%M:%S"
        }
        , "simple": {
            "format": "%(asctime)s [%(levelname)s] %(message)s"
            , "datefmt": "%Y-%m-%d %H:%M:%S"
        }
        , "db": {
            "format": "%(asctime)s (%(duration).2f ms) %(sql)s"
            , "datefmt": "%Y-%m-%d %H:%M:%S"
        }
    }
    , "handlers": {
        "file_logger": {
            "level": "DEBUG"
            , "class": "logging.handlers.RotatingFileHandler"
#            , "class": "logging.FileHandler"
            , "formatter": "verbose"
            , "maxBytes": 1024 * 500
            , "backupCount": 3
            , "filename": os.path.join(MEDIA_ROOT, "logs", "ittc.log")
        }
        , "file_db_logger": {
            "level": "DEBUG"
            , "class": "logging.handlers.RotatingFileHandler"
            , "formatter": "db"
            , "maxBytes": 1024 * 2048
            , "backupCount": 5
            , "filename": os.path.join(MEDIA_ROOT, "logs", "db.log")
        }
        , "console": {
            "level": "DEBUG"
            , "class": "logging.StreamHandler"
            , "formatter": "db"
        }
        , "null": {
            "level": "DEBUG"
            , "class": "django.utils.log.NullHandler"
        }
    }
    , "loggers": {
        "": {
            "handlers": ["file_logger"]
            , "level": "DEBUG"
            , "propagate": True
        },
        "django.db.backends": {
            "handlers": ["null"]
            , "level": "DEBUG"
            , "propagate": False
        }
    }
}

CACHES = {
    "default": {
        "BACKEND": "django.core.cache.backends.locmem.LocMemCache"
#        , "LOCATION": "unique-cachename"
    }
}
